package structs;

public class StorageLines {
	String[] fDataArray;
	private int MaxAlert;// Limite para parar leitura de arquivo
	private int MinAlert;// liminte para continuar leitura de arquivos
	private int first = 0;
	private int last = 0;
	private int count = 0;
	
	
	public StorageLines(int aSize){
		fDataArray = new String[aSize];
	}

	
	public void insertLine(String value) throws InterruptedException{
		while (count == MaxAlert){
			wait();
		}
		fDataArray[last] = value;
		last = (last + 1) % MaxAlert ;
		count ++;
		notifyAll();
	}
	
	public synchronized String get() throws InterruptedException{
		while (count == 0){
			wait();
		}
		String xData = fDataArray[first];
		first =  (first + 1) % MaxAlert;
		count --;
		while(count == MinAlert){
			notifyAll();
		}
		return xData;
	}
	
}
